//
//  OrderDetailView.m
//  HMSupplier
//
//  Created by haohao on 2017/7/6.
//  Copyright © 2017年 haohao. All rights reserved.
//

#import "OrderDetailView.h"

#define alertHeight 290

#define alertWidth KWidthSCREEN - 30 * 2

#define alerty 115

#define marin  10

#define imageWe 35

#define imageMarin 20

#define imageWidth (alertWidth - imageWe * 2 - imageMarin * 2) / 3

@interface OrderDetailView ()

NS_STRONG UIView *alertView;

@end

@implementation OrderDetailView

- (instancetype)initWithFrame:(CGRect)frame {
    self = [super initWithFrame:frame];
    if (self) {
        self.backgroundColor = [UIColor colorWithRed:0 green:0 blue:0 alpha:0.4];
        self.frame = CGRectMake(0, 0, KWidthSCREEN, KHeightSCREEN);
        [self setUpSubView];
    }
    return self;
}

- (void)setUpSubView {
    _alertView = [[UIView alloc] initWithFrame:CGRectMake(30, alerty, alertWidth, alertHeight)];
    _alertView.backgroundColor = [UIColor whiteColor];
    _alertView.layer.cornerRadius = 5;
    _alertView.clipsToBounds = YES;
    
    UILabel *reasonTitleLabel = [[UILabel alloc] initWithFrame:CGRectMake(marin, 15, alertWidth - marin, 30)];
    reasonTitleLabel.text = @"退货原因";
    reasonTitleLabel.font = [UIFont systemFontOfSize:13.0];
    [_alertView addSubview:reasonTitleLabel];
    
    UILabel *reasonLabel = [[UILabel alloc] initWithFrame:CGRectMake(marin, CGRectGetMaxY(reasonTitleLabel.frame) + marin, alertWidth - marin * 2, 95)];
    reasonLabel.backgroundColor = kf5f5f5;
    reasonLabel.font = [UIFont systemFontOfSize:13.0];
    [_alertView addSubview:reasonLabel];
    
    UILabel *totalTitleWeight = [[UILabel alloc] initWithFrame:CGRectMake(marin, CGRectGetMaxY(reasonLabel.frame) + 15, 40, 20)];
    totalTitleWeight.text = @"退货量";
    totalTitleWeight.font = [UIFont systemFontOfSize:13.0];
    [_alertView addSubview:totalTitleWeight];
    
    UILabel *weightLabel = [[UILabel alloc] initWithFrame:CGRectMake(CGRectGetMaxX(totalTitleWeight.frame) + marin, totalTitleWeight.frame.origin.y, 100, 20)];
    weightLabel.text = @"3斤";
    weightLabel.font = [UIFont systemFontOfSize:13.0];
    weightLabel.textColor = [UIColor redColor];
    [_alertView addSubview:weightLabel];
    
    UILabel *imageTitleLabel = [[UILabel alloc] initWithFrame:CGRectMake(marin, CGRectGetMaxY(weightLabel.frame) + 15, 50, 20)];
    imageTitleLabel.text = @"图片";
    imageTitleLabel.font = [UIFont systemFontOfSize:13.0];
    [_alertView addSubview:imageTitleLabel];
    
    float height = 0.0;
    for (int i = 0; i < 3; i++) {
        UIImageView *imageVI = [[UIImageView alloc] initWithFrame:CGRectMake(imageWe + imageMarin * i + imageWidth * i, CGRectGetMaxY(imageTitleLabel.frame) + marin, imageWidth, imageWidth)];
        imageVI.backgroundColor = [UIColor redColor];
        [_alertView addSubview:imageVI];
        height = CGRectGetMaxY(imageVI.frame);
    }
    _alertView.frame = CGRectMake(30, alerty, alertWidth, height + 20);
    
    [self addSubview:_alertView];
    
    UIButton *dismissBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    dismissBtn.frame = CGRectMake(KWidthSCREEN / 2 - marin, CGRectGetMaxY(_alertView.frame) + 15, 40, 40);
    [dismissBtn setImage:[UIImage imageNamed:@"peopleCenter_detail_close"] forState:UIControlStateNormal];
    [dismissBtn addTarget:self action:@selector(dismiss) forControlEvents:UIControlEventTouchUpInside];
    [self addSubview:dismissBtn];
}

- (void)show {
    UIWindow *window = [UIApplication sharedApplication].keyWindow;
    [window addSubview:self];
    self.alpha = 0;
    self.alertView.transform = CGAffineTransformMakeScale(1.08, 1.08);
    [UIView animateWithDuration:0.3 animations:^{
        self.alpha = 1;
        self.alertView.transform = CGAffineTransformIdentity;
    }];
}


- (void)dismiss {
    [UIView animateWithDuration:0.38 animations:^{
        self.alpha = 0;
    }completion:^(BOOL finished) {
        [self removeFromSuperview];
    }];
}

@end
